//
//  OriginalView.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/20.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

import SDWebImage

class OriginalView: UIView {
    
    var userInfo:WeiboCellViewModel?{
        didSet{
            //头像图片
            //TODO: 如果没有图片的话怎么处理?
            icon?.sd_setImageWithURL(NSURL(string: (userInfo?.status!.user?.profile_image_url) ?? ""))
          
            //name
            name?.text = userInfo?.status!.user?.screen_name
            
            //TODO: 设置vip
            vip?.image = userInfo?.VipImage
            
            //时间
            time?.text = userInfo?.time
            //来源
            original?.text = userInfo?.source
           //content
            content?.text = userInfo?.status?.text
            
            
        }
    }
   
    override init(frame: CGRect) {
        super.init(frame: frame)
         self.backgroundColor = KsubviewColor
        
        
        self.setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        self.addSubview(icon!)
        //头像的位置
        
        icon?.snp_makeConstraints(closure: { (make) -> Void in
            make.top.leading.equalTo(self).offset(CellMagin)
            make.width.height.equalTo(StatusCellHeadImgWH)
        })
        //昵称的位置
        self.addSubview(name!)
        name?.text = "哈哈"
        name?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(icon!.snp_trailing).offset(CellMagin)
            make.top.equalTo(icon!.snp_top)
        })
        //会员标注的位置
        
        self.addSubview(vip!)
        vip?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(name!.snp_trailing).offset(CellMagin)
            make.top.equalTo(name!.snp_top)
        })
        //时间的约束
        self.addSubview(time!)
        time?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(icon!.snp_trailing).offset(CellMagin)
            
            make.bottom.equalTo(icon!.snp_bottom)
        })
        //来源的约束
        self.addSubview(original!)
        original!.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(time!)
            make.leading.equalTo(time!.snp_trailing).offset(CellMagin)
        }
        // content 的约束
        self.addSubview(content!)
        content?.snp_makeConstraints(closure: { (make) -> Void in
            make.top.equalTo((icon?.snp_bottom)!).offset(CellMagin)
            make.leading.equalTo(self).offset(CellMagin)
        })
        //自己的约束用来调整行高
        //TODO: 如何确保已经加到了superview上面
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo((content?.snp_bottom)!).offset(CellMagin)
        }
    }
    
    
    
    // MARK -   懒加载控件
    
    lazy var icon:UIImageView? = {
        let imageView = UIImageView(image: UIImage(named: "avatar_default"))
        return imageView
    }()
    
    lazy var name:UILabel? = {
       let nameLabel = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 14)
        return nameLabel
    }()
    
    lazy var vip:UIImageView? = {
       let imageView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
        
        return imageView
    }()
    
    //时间
    lazy var time:UILabel? = {
       let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 12)
        label.text = "早行号啊"
        return label
    }()
    //来源
    lazy var original:UILabel? = {
       let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 12)
        label.text = "来自我的iphone"
        return label
    }()
    
    //微博内容
    lazy var content:UILabel? = {
       let label = UILabel(textColor: UIColor.darkTextColor(), fontSize: 13, preferredMaxLayoutWidth: KcontentW)
        
        
        return label
    }()
    
    
}
